#include <iostream>
#include <set>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;

namespace fastio{
    inline int in(){
        int x=0,f=1;
        char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
        return x*f;
    }
    int stk[30],tp;
    inline void out(int x){
        if(x<0){
            putchar('-');
            x = -x;
        }
        do stk[++tp]=x%10,x/=10;while(x);
        while(tp)putchar(stk[tp--]^48);
    }
}
using fastio::in;
using fastio::out;

typedef pair<int,int> PII;
const int N = 100005,INF = 0x3f3f3f3f3f3f3f3f;
multiset<int> s;
PII a[N];
int n;

signed main(){
    freopen("boast.in","r",stdin);
    freopen("boast.out","w",stdout);
    n = in();
    for(int k=1;k<=n;k++){
        a[k].first = in();
        a[k].second = in();
    }
    sort(a+1,a+1+n,[](PII x,PII y){return x.second==y.second?x.first<y.first:x.second>y.second;});
    s.insert(a[1].first+a[1].second);
    s.insert(a[2].first+a[2].second);
    int ans = INF;
    for(int k=3;k<=n;k++){
        ans = min((*s.begin())+(*(++s.begin()))+a[k].first,ans);
        s.insert(a[k].first+a[k].second);
    }
    out(ans);
    return 0;
}